New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix the build on OpenBSD #1333
Fix the build on OpenBSD #1333
Conversation
code/scripting/lua/LuaTable.h
Outdated
@@ -19,7 +19,7 @@ class LuaTable; | |||
* be in the exact same state when you call the next method of this class. | |||
*/ | |||
class LuaTableIterator { | |||
lua_State* _L = nullptr; | |||
lua_State* L_State = nullptr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rest of the class uses the format _varname
so this field should do the same. _luaState
would be an acceptable name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah. I was reluctant to do that originally because leading underscores are theoretically reserved for the standard headers...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only global names beginning with an underscore are reserved. For names in non-global namespaces (e.g. a class) the name may begin with an underscore but the next letter must be lower case which also explains why _L
is an invalid name.
The static assert is needed to ensure that no runtime errors occur but it could be conditionally enabled only if support for |
The iterator known as _L, besides having an absurdly poor name, clashes with standard headers on OpenBSD -current at the time of writing. This commit is the minimum needed to build on OpenBSD with an updated C++ standard library.
I've just added a platform check for is_trivially_copyable, can split off into another PR if desired. |
cmake/platformChecks.cmake
Outdated
@@ -16,6 +17,9 @@ CHECK_TYPE_SIZE("max_align_t" MAX_ALIGN_T) | |||
|
|||
set(CMAKE_EXTRA_INCLUDE_FILES "cstddef") | |||
CHECK_TYPE_SIZE("std::max_align_t" STD_MAX_ALIGN_T LANGUAGE CXX) | |||
set(CMAKE_EXTRA_INCLUDE_FILES "type_traits") | |||
CHECK_TYPE_SIZE("std::is_trivially_copyable<int>" STD_IS_TRIVIALLY_COPYABLE LANGUAGE CXX) | |||
MESSAGE(${HAVE_STD_IS_TRIVIALLY_COPYABLE}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be working properly, although our Travis GCC config fails this test for some reason although it compiled the previous version properly. That doesn't matter though since Clang works properly.
Once you remove this test message, this is ready to be merged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, dammit. Thanks for catching... :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My local setup passes the test, by the way (6.3.0 in Debian testing). Unfortunately my machines all have either 'old' gcc (4.9) or new gcc (>6) at the moment; I'll try to investigate behavior on gcc 5 (Debian packages 5.4 at the moment, in testing).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason gcc5 fails the test appears to be quite simple and stupid - from CMakeError.txt:
/usr/include/c++/5/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
I should be able to push a fix shortly.
35d8427
to
b8f1d76
Compare
cmake/platformChecks.cmake
Outdated
@@ -16,6 +17,10 @@ CHECK_TYPE_SIZE("max_align_t" MAX_ALIGN_T) | |||
|
|||
set(CMAKE_EXTRA_INCLUDE_FILES "cstddef") | |||
CHECK_TYPE_SIZE("std::max_align_t" STD_MAX_ALIGN_T LANGUAGE CXX) | |||
set(CMAKE_EXTRA_INCLUDE_FILES "type_traits") | |||
set(CMAKE_REQUIRED_FLAGS "-std=c++11") # required for g++ <= 5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is only relevant for GCC it should be surrounded by a check for that compiler. if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
should work since that is the same string our toolchain detection uses.
Since this applies to all the C++ checks, could you insert that code above the other CHECK_TYPE_SIZE
? That will make the results more consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
cmake/platformChecks.cmake
Outdated
CHECK_TYPE_SIZE("std::max_align_t" STD_MAX_ALIGN_T LANGUAGE CXX) | ||
set(CMAKE_EXTRA_INCLUDE_FILES) | ||
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") | ||
set(CMAKE_REQUIRED_FLAGS "-std=c++11") # required for g++ <= 5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not what I meant. Only this line should be in the if body. The other lines are required on all platforms but -std=c++11
is only relevant for GCC.
This is how it should look like:
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(CMAKE_REQUIRED_FLAGS "-std=c++11") # required for g++ <= 5
endif()
set(CMAKE_EXTRA_INCLUDE_FILES "cstddef")
CHECK_TYPE_SIZE("std::max_align_t" STD_MAX_ALIGN_T LANGUAGE CXX)
set(CMAKE_EXTRA_INCLUDE_FILES "type_traits")
CHECK_TYPE_SIZE("std::is_trivially_copyable<int>" STD_IS_TRIVIALLY_COPYABLE LANGUAGE CXX)
set(CMAKE_EXTRA_INCLUDE_FILES)
set(CMAKE_REQUIRED_FLAGS)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, sorry.
Yes, the template instantiation appears necessary for cmake to detect the type. If there's a better type for it than int, I'm open to suggestions.
Yes, that looks good now. |
FSO doesn't build from source on OpenBSD anymore. This patch corrects the only significant problem: the iterator in LuaTable.h/cpp known as _L clashes with a #define in OpenBSD's standard headers (ctypes.h to be specific). The new name proposed here is simply taken from the type.
One other problem still prevents building on OpenBSD at this time: an assert in code/scripting/ade.h that calls std::is_trivially_copyable, available in libstdc++ >= 5 (where OpenBSD has 4.9 in ports/packages). OpenBSD on i386/amd64 will probably use clang/libc++ in the future, so this issue will go away anyhow. For the record, the following diff on top of this PR fixes the build on OpenBSD 6.1-current at this time: